package com.itbaizhan.shopping_manager_api.controller;

/**
 * @author spf
 * @date 2023/12/28
 * @time 9:39
 */

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.itbaizhan.shopping_common.pojo.SeckillGoods;
import com.itbaizhan.shopping_common.result.BaseResult;
import com.itbaizhan.shopping_common.service.SecKillGoodsService;
import org.apache.dubbo.config.annotation.Reference;
import org.springframework.web.bind.annotation.*;

/**
 * 秒杀商品API
 */
@RestController
@RequestMapping("/seckillGoods")
public class SecKillGoodsController {

    @Reference
    private SecKillGoodsService secKillGoodsService;

    /**
     * 新增秒杀商品
     * @param seckillGoods 秒杀商品对象
     * @return 执行结果
     */
    @PostMapping("/add")
    public BaseResult add(@RequestBody SeckillGoods seckillGoods){
        secKillGoodsService.add(seckillGoods);
        return BaseResult.ok();
    }

    /**
     * 修改秒杀商品结果
     * @param seckillGoods 秒杀商品对象
     * @return 执行结果
     */
    @PutMapping("/update")
    public BaseResult update(@RequestBody SeckillGoods seckillGoods){
        secKillGoodsService.update(seckillGoods);
        return BaseResult.ok();
    }

    /**
     * 分页查询秒杀商品
     * @param page 页码
     * @param size 每页条数
     * @return 执行结果
     */
    @GetMapping("/findPage")
    public BaseResult<Page<SeckillGoods>> findPage(int page, int size){
        Page<SeckillGoods> seckillGoodsPage = secKillGoodsService.findPage(page, size);
        return BaseResult.ok(seckillGoodsPage);
    }
}
